#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<vector<int>> res;
    void dfs(vector<int>& stor, map<int, int>& hash, int start)
    {
        res.push_back(stor);
        for (auto& pair : hash)
        {
            if (pair.first >= start && pair.second > 0)
            {
                stor.push_back(pair.first);
                --pair.second;
                dfs(stor, hash, pair.first);
                stor.pop_back();
                ++pair.second;
            }
        }
    }
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        map<int, int> hash;
        for (auto& e : nums)
        {
            ++hash[e];
        }
        vector<int> tmp;
        dfs(tmp, hash, -10);
        return res;
    }
};